package org.com.Controller;


import Entity.Comment;
import Entity.Community;
import Entity.Postlike;
import lombok.extern.slf4j.Slf4j;
import org.com.Service.ICommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 277
 * @since 2025-10-04
 */
@Slf4j
@RestController
@RequestMapping("/community")
public class CommunityController {
    @Autowired
    private ICommunityService ICommunityService;

    @GetMapping("/list")
    public List<Community> allblog() {
        return ICommunityService.getall();
    }

    @PostMapping("/save")
    public ResponseEntity<Community> save(@RequestBody Community community) {

        ICommunityService.save(community);

        return ResponseEntity.ok(community);
    }


    @PostMapping("/up")
    public Map<String, Object> up(@RequestBody Map<String, Object> community) {
        return ICommunityService.up(community);
    }

    @PostMapping("/down")
    public String down(@RequestBody Postlike postlike) {
        return ICommunityService.down(postlike);
    }

    @GetMapping("/host")
    public List<Community> host() {
        return ICommunityService.host();
    }

    @PostMapping("/comment")
    public List<Comment> comment(@RequestBody Map<String, Object> community) {
        return ICommunityService.comment(community);
    }

    @PostMapping("/delete/{id}")
    public Boolean delete(@PathVariable int id) {
        return ICommunityService.removeById(id);
    }
}
